<%@page import="org.eclipse.football.League"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="Style.css" />
<title>League Summary</title>
</head>
<body>

<%-- Display username and log out button--%>
<% // make sure username is initialized
String username = (String)request.getSession(true).getAttribute("username");

if(username==null){
	request.getSession().setAttribute("username", "");
	getServletContext().getRequestDispatcher("/LeagueSummary.jsp").forward(request, response);
}%>

<FORM action="/FootballStats/log_in" method="post">
<H1> Welcome <c:out value="${username}" />! </H1>
<P> Not <c:out value="${username}" />? 
<INPUT type="submit" name="button" value="Change Account">
</FORM>

<%
// Get the league from the session*
League league = (League) session.getValue("league");
if(league == null){
	// If the league is null instantiate a new one
	league = new League("league.txt");
}

// Set the league in the session
session.putValue("league", league);
%>

<!-- Team Offensive Summary Table Start -->
<!-- Team Offensive Summary Header Start -->
<table border="1" cellspacing="0">
<tr>
<th align="center" valign="middle" width="100">
Team
</th>
<th align="center" valign="middle">
Owner
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="20"></input>
<input type="submit" name="Points" value="Points"></input>
</form>
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="0"></input>
<input type="submit" name="Pass YDs" value="Pass YDs"></input>
</form>
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="1"></input>
<input type="submit" name="Pass TDs" value="Pass TDs"></input>
</form>
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="2"></input>
<input type="submit" name="INTs" value="INTs"></input>
</form>
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="3"></input>
<input type="submit" name="Rush YDs" value="Rush YDs"></input>
</form>
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="4"></input>
<input type="submit" name="Rush TDs" value="Rush TDs"></input>
</form>
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="5"></input>
<input type="submit" name="Rec. YDs" value="Rec. YDs"></input>
</form>
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="6"></input>
<input type="submit" name="Rec. TDs" value="Rec. TDs"></input>
</form>
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="7"></input>
<input type="submit" name="Fumbles" value="Fumbles"></input>
</form>
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="8"></input>
<input type="submit" name="Return TDs" value="Return TDs"></input>
</form>
</th>
</tr>
<!-- Team Offensive Summary Header End -->

<!-- Team Offensive Summary Row Start -->
<c:forEach items="${league.teams}" var="team">
<tr>
<td>
<form action="/FootballStats/pick_team" method="post">
<input type="hidden" name="name" value="${team.getName() }"></input>
<input type="submit" name="PickTeam" value="${team.getName() }"></input>
</form>
</td>
<td>
<c:out value="${team.getUsername() }"/>
</td>
<td>
<c:out value="${team.calculatePoints() }"/>
</td>
<td>
<c:out value="${team.getPassYds() }"/>
</td>
<td>
<c:out value="${team.getPassTds() }"/>
</td>
<td>
<c:out value="${team.getPicks() }"/>
</td>
<td>
<c:out value="${team.getRushYds() }"/>
</td>
<td>
<c:out value="${team.getRushTds() }"/>
</td>
<td>
<c:out value="${team.getRecYds() }"/>
</td>
<td>
<c:out value="${team.getRecTds() }"/>
</td>
<td>
<c:out value="${team.getFumbles() }"/>
</td>
<td>
<c:out value="${team.getRetTds() }"/>
</td>
</tr>
</c:forEach>
<!-- Team Offensive Summary Row End -->
</table>
<!-- Team Offensive Summary Table End -->


<br>
<br>


<!-- Team Defensive Summary Table Start-->
<table border="1" cellspacing="0">
<!-- Team Defensive Summary Head Start -->
<tr>
<th align="center" valign="middle" width="100">
Team
</th>
<th align="center" valign="middle">
Owner
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_def" method="post">
<input type="hidden" name="type" value="8"></input>
<input type="submit" name="Points" value="Points"></input>
</form>
</th>
<!-- <th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="9"></input>
<input type="submit" name="Defensive Touchdowns" value="Defensive Touchdowns"></input>
</form>
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="10"></input>
<input type="submit" name="Defensive Interceptions" value="Defensive Interceptions"></input>
</form>
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="11"></input>
<input type="submit" name="Fumbles Recovered" value="Fumbles Recovered"></input>
</form>
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="12"></input>
<input type="submit" name="Sacks" value="Sacks"></input>
</form>
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="13"></input>
<input type="submit" name="Blocked Kicks" value="Blocked Kicks"></input>
</form>
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="14"></input>
<input type="submit" name="Safeties" value="Safeties"></input>
</form>
</th> -->
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="15"></input>
<input type="submit" name="Points Allowed" value="Points Allowed"></input>
</form>
</th>
<!-- <th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="16"></input>
<input type="submit" name="Yards Allowed" value="Yards Allowed"></input>
</form>
</th> -->
</tr> 
<!-- Team Defensive Summary Head End -->


<!-- Team Defensive Summary Row Start -->
<c:forEach items="${league.teams}" var="team">
<tr>
<td>
<form action="/FootballStats/pick_team" method="post">
<input type="hidden" name="name" value="${team.getName() }"></input>
<input type="submit" name="PickTeam" value="${team.getName() }"></input>
</form>
</td>
<td>
<c:out value="${team.getUsername() }"/>
</td>
<td>
<c:out value="${team.calculateDefPoints() }"/>
</td>
<%-- <td>
<c:out value="${team.getDefTds() }"/>
</td>
<td>
<c:out value="${team.getDefPicks() }"/>
</td>
<td>
<c:out value="${team.getDefFumbles() }"/>
</td>
<td>
<c:out value="${team.getSacks() }"/>
</td>
<td>
<c:out value="${team.getBlocks() }"/>
</td>
<td>
<c:out value="${team.getSafeties() }"/>
</td> --%>
<td>
<c:out value="${team.getPA() }"/>
</td>
<%-- <td>
<c:out value="${team.getYA() }"/>
</td> --%>
</tr>
</c:forEach>
<!-- Team Defensive Summary Row End -->
</table>
<!-- Team Defensive Summary Table End -->


<br>
<br>


<!-- Team Kicking Summary Table Start-->
<table border="1" cellspacing="0">
<!-- Team Kicking Summary Head Start -->
<tr>
<th align="center" valign="middle" width="100">
Team
</th>
<th align="center" valign="middle">
Owner
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_def" method="post">
<input type="hidden" name="type" value="8"></input>
<input type="submit" name="Points" value="Points"></input>
</form>
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="17"></input>
<input type="submit" name="PAT Made" value="PAT Made"></input>
</form>
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="18"></input>
<input type="submit" name="FG Made" value="FG Made"></input>
</form>
</th>
<th align="center" valign="middle">
<form action="/FootballStats/sort_team" method="post">
<input type="hidden" name="type" value="19"></input>
<input type="submit" name="FG Missed" value="FG Missed"></input>
</form>
</th>
</tr>
<!-- Team Kicking Summary Head End -->


<!-- Team Kicking Summary Row Start -->
<c:forEach items="${league.teams}" var="team">
<tr>
<td>
<form action="/FootballStats/pick_team" method="post">
<input type="hidden" name="name" value="${team.getName() }"></input>
<input type="submit" name="PickTeam" value="${team.getName() }"></input>
</form>
<td>
<c:out value="${team.getUsername() }"/>
</td>
<td>
<c:out value="${team.calculateKickPoints() }"/>
</td>
<td>
<c:out value="${team.getPAT() }"/>
</td>
<td>
<c:out value="${team.getFG() }"/>
</td>
<td>
<c:out value="${team.getMisses() }"/>
</td>
</tr>
</c:forEach>
<!-- Team Kicking Summary Row End -->
</table>
<!-- Team Kicking Summary Table End -->



<form action="/FootballStats/teams" method="post">
<BR>
Team Name: <input type="text" name="name" size="35">
<br>
<input type="submit" name="Team Button" value="Add Team">
</form>

</body>
</html>